//
//  ExamPlayInfoController.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/11/8.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "ExamPlayInfoController.h"
#import "UIViewController+Ext.h"
#import "OrderListCell.h"
#import "MJRefresh.h"
#import "ExamPlayListModel.h"
#import "ExamPlayInfoModel.h"
#import "TrackReplayView.h"

@interface ExamPlayInfoController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSInteger page;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *listArray;

@property (nonatomic, strong) TrackReplayView *replayView;
@property (nonatomic, strong) ExamPlayInfoModel *examPlayInfo;
@end

@implementation ExamPlayInfoController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[CoachTabBarController shareLZHTabbarController].tabBar setHidden:YES];
    [self reloadMessage];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationItem setTitle:@"模拟回放"];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self setNavBack];
    
    CGRect viewFrame = self.view.bounds;
    TrackReplayView *replayView = [[TrackReplayView alloc] initWithFrame:viewFrame];
    //    [replayView reloadFrame:CGSizeMake(6768, 6000)];
    [self.view addSubview:replayView];
    self.replayView = replayView;
    self.listArray = [[NSMutableArray alloc] init];
    self.examPlayInfo = [[ExamPlayInfoModel alloc] init];
}

#pragma mark - 获取消息
- (void)reloadMessage{
    [self showLoading];
    [self.listArray removeAllObjects];
    page = 1;
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithLong:self.detail.ID], @"mockscoreId", nil];
    [[NetworkEngine sharedClient] GETByToken:TEACHSIMULATIONVIDEO data:parameters success:^(id responseObject) {
        [self.tableView.mj_header endRefreshing];
        NSDictionary *JSON = (NSDictionary *)responseObject;
        if ([JSON isKindOfClass:[NSDictionary class]]) {
            NSInteger status = [[JSON objectForKey:@"code"] integerValue];
            if (status == 1) {
                NSArray *data = [[JSON objectForKey:@"data"] objectForKey:@"trajector"];
                if ([data isKindOfClass:[NSArray class]]) {
                    NSArray *dataList = [ExamPlayInfo mj_objectArrayWithKeyValuesArray:data];
                    [self.examPlayInfo setPlayInfo:dataList];
                    [self.examPlayInfo dataOperate];
                    [self.replayView reloadDrawing:self.examPlayInfo.playInfoRate :self.examPlayInfo.videoLength];
                }
            }
            else if (status == 2) {
                [self toLoginVC];
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
        }
        
        [self hideHUD];
    } failure:^(NSString *error) {
        [self hideHUD];
        [self.tableView.mj_header endRefreshing];
    }];
}


@end
